﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WP09S03_OfficeTracking.ParentClass
{
    public partial class ParentForm : Form
    {
        public ParentForm()
        {
            InitializeComponent();
        }

        protected bool IsShowMessageBox = false;

        public void RefreshWarnningText() { 
        //Refresh the replenish qty and due text
        //Replenish qty

            Controller.ItemController ic = new Controller.ItemController();

            lblReplenish.Visible = false;
            lblReplenishQty.Visible = false;

            int ret = ic.GetItemCountReplenish();
            if (ret>0) {
                lblReplenish.Visible = true ;
                lblReplenishQty.Visible = true;
                lblReplenishQty.Text  = Convert.ToString(ret);
            }
      

       //Due return qty

            lblDueReturnQty.Visible = false;
            lblDueReturn.Visible = false;

            ret = ic.GetItemCountDueReturn();
            if (ret > 0)
            {
                lblDueReturn.Visible = true;
                lblDueReturnQty.Visible = true ;
                lblDueReturnQty.Text = Convert.ToString(ret);
            }
        
        }

        public void SetMessage(String strMessage) {
            lblMessage.Text = strMessage;
            timer1.Enabled = true;
          //  timer1.Start();
        }

        public void SetSubtitle(String strTitle)
        {
            lblSubTitle.Text = strTitle;
        }


        public string GetSubtitle()
        {
          return   lblSubTitle.Text;
        }

        private void ParentForm_Load(object sender, EventArgs e)
        {
            RefreshWarnningText();
            lblMessage.Text = "";
           // this.Text = "";

        }

        private void lblReplenishQty_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            DiagReplenishWarning dg = new DiagReplenishWarning();

            dg.ShowDialog();
        }

        private void lblDueReturnQty_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            DiagDueReturn dg = new DiagDueReturn();
            dg.ShowDialog();
        }

        protected void CatchError(Exception ex)
        {
            SetMessage(ex.Message);
            if (IsShowMessageBox)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        protected  DialogResult  ShowDeleteConfirm() {
           return MessageBox.Show("Are you sure to delete this record?", "Delete Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            lblMessage.Text = "";
           // timer1.Stop();
            timer1.Enabled = false ;
        }

    }
}
